<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/pageHead.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资金云平台密码重置</title>
<link href="${systemctx }/resources/css/base.css" rel="stylesheet" type="text/css" media="all" />
<link href="${systemctx }/resources/validform/css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href="${systemctx }/resources/css/list.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="${systemctx }/resources/validform/js/Validform_v5.3.2.js"></script>
</head>
<body>
	<form action="${systemctx}/login/modifyPassword.json" class="registerform" method="post" id=modifyform name="modifyform">
		<div class="panel-header">
			<div class="panel-title">
				<%=MessageResourcesUtils.getMessage(request, "common.password.edit") %>
			</div>
		</div>	
		<div class="pageBody">
			<div class="form-group vali-list">
				<input type="hidden" name="id" id="id" value="${userid}">
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request, "common.password.old") %>
						</label>
						<span>
							<input type="password" value="" name="oldPassword" id="passwordold" datatype="s6-18" nullmsg="<%=MessageResourcesUtils.getMessage(request, "common.password.input.old.password") %>" errormsg="<%=MessageResourcesUtils.getMessage(request, "systemtmanage.user.password.old") %>" />
						</span>
						<span>
							<div class="Validform_checktip" id="old_password"></div>
						</span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request, "common.password.new") %>
						</label>
						<span>
							<input ajaxurl="${systemctx}/systemmanage/resetManageUser/isValidByTop.json?userid=${userid}" type="password" value="" id="userpassword"
								name="userpassword" 
								nullmsg="<%=MessageResourcesUtils.getMessage(request, "common.password.input.new.password")%>"
								datatype="oldpassword,*8-20"
								errormsg="<%=MessageResourcesUtils.getMessage(request, "common.password.min.max")%>" />
						</span>
						<span>
							<div class="Validform_checktip" id="userpassword_error"></div>
						</span>
					</li>
				</ul>
				<ul>
					<li>
						<div class="pass-vali">
							<p id="strength_L"><%=MessageResourcesUtils.getMessage(request, "common.password.weak") %></p>
							<p id="strength_M"><%=MessageResourcesUtils.getMessage(request, "common.password.normal") %></p>
							<p id="strength_H"><%=MessageResourcesUtils.getMessage(request, "common.password.strong") %></p>
						</div>
					</li>
				</ul>
				<ul>
					<li>
		                <i>*</i>
		                <label>
		                 	<%=MessageResourcesUtils.getMessage(request, "common.password.sure") %>
		                </label>
		                <span>
		                 	<input type="password" value="" name="userpassword2" 
		                 		datatype="*" recheck="userpassword" 
		                 		nullmsg="<%=MessageResourcesUtils.getMessage(request, "common.password.input.again") %>" 
		                 		errormsg="<%=MessageResourcesUtils.getMessage(request, "common.password.two.password.difference") %>" />
	                 	</span>
		                <span><div class="Validform_checktip"></div></span>
					</li>
				</ul>
	     	</div>
	     	<div class="button-group">
	     		<button  type="submit" id="btn_submit" class="btn btn-default">
                     		<%=MessageResourcesUtils.getMessage(request, "common.button.update") %>
                   	</button>
                   	<button  type="reset" id="btn_reset" class="btn btn-default">
                   		<%=MessageResourcesUtils.getMessage(request, "common.button.reset") %>
			 	</button>
	     	</div>
     	</div>
     </form>
</body>
<script type="text/javascript">
	$(document).ready(function() {
		$(".registerform").Validform({
			btnSubmit : "#btn_sub",
			btnReset : ".btn_reset",
			tiptype : 2,
			ignoreHidden : false,
			dragonfly : false,
			tipSweep : true,
			label : ".label",
			showAllError : false,
			postonce : true,
			ajaxPost : true,
			datatype : {
				"oldpassword" : function(gets) {
					if (gets == $("#passwordold").val()) {
						return "<%=MessageResourcesUtils.getMessage(request, "common.password.difference")%>";
					}
				}
			},
			beforeSubmit : function() {
				//在验证成功后，表单提交前执行的函数，curform参数是当前表单对象。
				//这里明确return false的话表单将不会提交;
				// 显示进度条
				showSending();
				/* modifyform.action="${systemctx}/login/modifyPassword.json";
				modifyform.submit(); */
			},
			callback : function(data) {
				//关闭执行...
				closeSending();
				if (data.messagetype == '2') {
					alert(data.message);
					return;
				} else {
					alert(data.message);
					window.parent.location.href = "${systemctx}/";
				}
			}
		});
		$('#userpassword').keyup(function(e) {
			var pwd = $(this).val();
			if(pwd != '') {
				if (pwd.length<8 || pwd.length>20) {
					$("#userpassword_error").addClass("Validform_wrong").html('<%=MessageResourcesUtils.getMessage(request, "common.password.min.max")%>');
					$("#btn_submit").attr('disabled',false)
					return ;
				}
			}
			pwStrength($(this).val());
		});
		
		$("#btn_reset").click(function(){
			$("#btn_submit").attr('disabled',false);
			pwStrength($(this).val());
		});
		
		$("#passwordold").keyup(function(){
			var old = $("#passwordold").val();
			if(old.length >= 6 && old.length <= 20){
				$("#old_password").removeAttr("class");
				$("#old_password").html('');
			}else {
				if($("#old_password").hasClass("Validform_right")){
					$("#old_password").removeClass('Validform_right');
					$("#old_password").html('');
				}else {
					$("#old_password").attr('class','Validform_checktip Validform_wrong');
					$("#old_password").html('<%=MessageResourcesUtils.getMessage(request, "systemtmanage.user.password.old")%>');
				}
				
			}
		});
	});

	//------------------------------------------------------------------

	function CharMode(ch) {
		if (ch >= 48 && ch <= 57) //数字   
			return 1;
		if (ch >= 65 && ch <= 90) //大写字母   
			return 2;
		if (ch >= 97 && ch <= 122) //小写   
			return 4;
		else
			return 8; //特殊字符 
	}
	function bitTotal(num) {
		var modes = 0;
		for (var i = 0; i < 4; i++) {
			if (num & 1)
				modes++;
			num >>>= 1;
		}
		return modes;
	}
	function checkStrong(pwd) { //返回密码的强度级别 
		if (pwd.length < 8)
			return 0;
		var Modes = 0;
		for (i = 0; i < pwd.length; i++) {
			//测试每一个字符的类别并统计一共有多少种模式. 
			Modes |= CharMode(pwd.charCodeAt(i));
		}
		return bitTotal(Modes);
	}
	function pwStrength(pwd) {
		if(pwd == ''){
			$("#userpassword_error").addClass("Validform_wrong").html('<%=MessageResourcesUtils.getMessage(request, "common.password.input.new.password")%>');
			$("#btn_submit").attr('disabled',false)
			document.getElementById("strength_L").style.background = "#FFFFFF";
			document.getElementById("strength_M").style.background = "#FFFFFF";
			document.getElementById("strength_H").style.background = "#FFFFFF";
			return false;
		}
		var O_color = "#eeeeee";
		var L_color = "#FF0000";
		var M_color = "#FF9900";
		var H_color = "#33CC00";
		if (pwd == null || pwd == '') {
			Lcolor = Mcolor = Hcolor = O_color;
		} else {
			var S_level = checkStrong(pwd);
			switch (S_level) {
			case 0:
				Lcolor = Mcolor = Hcolor = O_color;
			case 1:
				Lcolor = L_color;
				Mcolor = Hcolor = O_color;
				break;
			case 2:
				Lcolor = Mcolor = M_color;
				Hcolor = O_color;
				break;
			default:
				if(pwd.length < 8){
					Lcolor = Mcolor = M_color;
					Hcolor = O_color;
				} else {
					Lcolor = Mcolor = Hcolor = H_color;
				}
				
			}
		}
		document.getElementById("strength_L").style.background = Lcolor;
		document.getElementById("strength_M").style.background = Mcolor;
		document.getElementById("strength_H").style.background = Hcolor;
		if($("#passwordold").val() == $("#userpassword").val()){
			$("#userpassword_error").addClass("Validform_wrong").html("<%=MessageResourcesUtils.getMessage(request, "common.password.difference")%>");
			return false;
		}
		if(S_level == 0 || S_level == 1){
			$("#userpassword_error").addClass("Validform_wrong").html('<%=MessageResourcesUtils.getMessage(request, "common.password.input.new.password.weak")%>');
			$("#btn_submit").attr('disabled',true)
			return false;
		}else {
			$("#btn_submit").attr('disabled',false)
			$("#userpassword_error").removeClass("Validform_wrong").addClass("Validform_right").html('<%=MessageResourcesUtils.getMessage(request, "common.password.input.new.password.pass")%>');
		}
		return;
	}
</script>
</html>